#include <iostream>
#include "remarkdao_impl.h"
#include <unistd.h>
#include <stdio.h>
#include "remark.h"

using namespace std;

void RemarkDaoImpl::load(vector<Remark>& remarks)
{
	FILE* frp = fopen("account/remarks.dat","rb");
	if(frp == NULL)
	{
		return;
	}
	remarks.clear();

	int num1 = 0; 
	fread(&num1,sizeof(int),1,frp);
	for(int i=0;i<num1;i++)
	{
		Remark* remark= new Remark;
		fread(remark,sizeof(Remark),1,frp);
		remarks.push_back(*remark);
	}
	fclose(frp);
	return;
}

void RemarkDaoImpl::save(vector<Remark>& remarks)
{
	FILE* fwp = fopen("account/remarks.dat","wb");
	if(fwp == NULL)
	{
		perror("fopen");
		return;
	}
	int num1 = remarks.size();	
	fwrite(&num1,1,sizeof(int),fwp);
	for(unsigned int i=0; i<remarks.size(); i++)
	{
		fwrite(&remarks[i],1,sizeof(Remark),fwp);
	}
	fclose(fwp);
}
